﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace LaughingDog.Managers
{
    public sealed class TimeManager : GameComponent
    {
        #region Private Members

        private GameTime mGameTime = new GameTime();
        private Single mDelta = 0.0f;

        #endregion

        #region Public Properties

        /// <summary>
        /// The current game time.
        /// </summary>
        public GameTime CurrentTime { get { return mGameTime; } }
        
        /// <summary>
        /// The current frames delta time.
        /// </summary>
        public Single Delta { get { return mDelta; } }

        #endregion

        #region Singleton

        static readonly TimeManager instance = new TimeManager(Engine.Game);

        // Explicit static constructor to tell C# compiler
        // not to mark type as beforefieldinit
        static TimeManager()
        {
        }

        TimeManager(Game game) 
            : base (game) 
        {
        }

        public static TimeManager Instance
        {
            get
            {
                return instance;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Updates the TimeManager.
        /// </summary>
        /// <param name="gameTime">A snapshot of the current game time.</param>
        public override void Update(GameTime gameTime)
        {
            mGameTime = gameTime;
            mDelta = mGameTime.ElapsedGameTime.Milliseconds * 0.001f;

            base.Update(gameTime);
        }

        #endregion
    }
}

